package com.kerrykidz.system.util.sync;

import java.io.Serializable;
import java.util.Collection;

import org.apache.commons.lang3.StringUtils;

public abstract class BaseMessage implements Serializable {

	private static final long serialVersionUID = 1L;
	/*
	 * =true 普通表，=false关联表
	 */
	protected boolean isCommonTable = true;
	protected String primaryKey; // 主键字段
	protected String tableName; // 表名
	protected String primaryValue; // 主键value
	
	public abstract SqlAndParam getDeleteSql() throws SyncDataException;

	public String getValues(Collection<Object> values) {
		StringBuffer sb = new StringBuffer();
		if (this.isCommonTable)
			sb.append("?,");
		for (@SuppressWarnings("unused")
		Object c : values)
			sb.append("?,");
		sb.delete(sb.length() - 1, sb.length());
		return sb.toString();
	}

	public String getFlds(Collection<String> col) {
		StringBuffer sb = new StringBuffer();
		if (this.isCommonTable)
			sb.append(this.primaryKey).append(",");
		for (String c : col) {
			if (StringUtils.isNotBlank(c))
				sb.append(c).append(",");
		}
		sb.delete(sb.length() - 1, sb.length());
		return sb.toString();
	}
	
	public String getPrimaryKey() {
		return primaryKey;
	}

	public void setPrimaryKey(String primaryKey) {
		this.primaryKey = primaryKey;
	}

	public String getPrimaryValue() {
		return primaryValue;
	}

	public void setPrimaryValue(String primaryValue) {
		this.primaryValue = primaryValue;
	}
}
